from flask import request
from utils import Aliyun
from common import ApiResponse
import os

UPLOAD_PATH = os.path.join(os.path.dirname(__file__), 'picture')

def upload():
    picture = request.files.get('file')

    if not os.path.exists(UPLOAD_PATH):
        os.mkdir(UPLOAD_PATH)

    picture_name = picture.filename
    print(picture_name)

    picture_save_path = os.path.join(UPLOAD_PATH,picture_name)
    picture.save(picture_save_path)
    print(picture_save_path)

    url = Aliyun.Aliyun.upload_avatar(avatar_path=picture_save_path)
    return ApiResponse.ApiResponse.success(data=url)
